package com.gjt.stream;

import java.io.*;

/**
 * Created with Intel IDEA.
 * 数据流（DataStream）: 可以用二进制格式读写java的基本数据类型和字符串
 *
 *
 * @Auther: gjt
 * @Date: 2024/3/19 20:58
 */
public class DataStream {
    public int test(OutputStream out) throws IOException {
        DataOutputStream dataOutputStream = new DataOutputStream(out);
        // write 支持写入java 的八大数据类型
        dataOutputStream.write(4);
        dataOutputStream.writeChars("str");
        dataOutputStream.writeBytes("stre");
        dataOutputStream.writeUTF("stre");
        return 1;
    }
    public int test(InputStream in) throws IOException {
        DataInputStream dataInputStream = new DataInputStream(in);
        // write 支持写入java 的八大数据类型
        dataInputStream.readBoolean();
        dataInputStream.readByte();
        dataInputStream.readChar();
        dataInputStream.readInt();
        dataInputStream.readLong();
        dataInputStream.readFloat();
        dataInputStream.readDouble();
        dataInputStream.readUTF();
        dataInputStream.read(new byte[10]);
        dataInputStream.read(new byte[10], 1 ,23);
        dataInputStream.readFully(new byte[10]);
        dataInputStream.readFully(new byte[10], 1,23);

        // 读取用行结束符分隔的一行文本 ，返回字符串；大多数不能将非Ascii字符转成字节 （可用BufferedReader的readLine()代替）
        // 隐藏bug 并不总能将回车识别为行结束符
        dataInputStream.readLine();

        //读取无符号的字节和短整型,并返回等价的int  ,java中没有这些数据   读取c程序时可用
        dataInputStream.readUnsignedByte();
        dataInputStream.readUnsignedShort();
        return 1;
    }



    public static void main(String[] args) {

    }
}
